import 'package:flutter/material.dart';
import 'package:api/pages/provider/getX/demo/shop/shop_controller.dart';
import 'package:api/pages/provider/getX/demo/shop/shop_model.dart';
import 'package:get/get.dart';

class ShopItemWidget extends StatefulWidget {
  final GoodsBean goodsBean;
  ShopItemWidget(this.goodsBean);
  @override
  _ShopItemWidgetState createState() => _ShopItemWidgetState();
}

class _ShopItemWidgetState extends State<ShopItemWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      margin: EdgeInsets.only(top: 8),
      padding: EdgeInsets.all(10),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Image.asset(
            widget.goodsBean.cover,
            width: 100,
          ),
          Expanded(
            child: Container(
              padding: EdgeInsets.all(10),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisSize: MainAxisSize.min,
                children: [
                  Text(widget.goodsBean.title),
                  Text(widget.goodsBean.subTitle),
                  SizedBox(height: 16),
                  Row(children: [
                    Expanded(child: Text("${widget.goodsBean.price}")),
                    GestureDetector(
                      onTap: () {
                        widget.goodsBean.isCard = !widget.goodsBean.isCard;
                        setState(() {});
                        Get.find<ShopController>().addCard(widget.goodsBean);
                      },
                      child: Container(
                        alignment: Alignment.center,
                        padding: EdgeInsets.only(left: 12, right: 12),
                        decoration: BoxDecoration(
                          color: widget.goodsBean.isCard
                              ? Colors.yellow
                              : Colors.blueGrey,
                          borderRadius: BorderRadius.all(
                            Radius.circular(30),
                          ),
                        ),
                        width: 120,
                        child: Text(widget.goodsBean.isCard ? '移除购物车' : '加入购物车',
                            style: TextStyle(color: Colors.white)),
                      ),
                    )
                  ]),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}
